package com.mercury.controller;

import com.mercury.service.EmailService;
import com.mercury.util.Random;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 童
 * @createTime 2021/11/21 10:32
 * @projectName coffee-parent
 * @className EmailController.java
 * @description TODO
 */
@RestController
public class EmailController {
    @Autowired
    EmailService emailService;

    @PostMapping("/email")
    public Object sendEmail(@RequestParam("emailAddress") String emailAddress) {
        try {
            String code = Random.generateVerCode();
            emailService.sendEmailVerCode(emailAddress,code);
            return code;
        } catch (Exception e) {
            return "邮件发送失败";
        }
    }
}
